//
//  MTRecomdAppCell.m
//  ShiShiBang
//
//  Created by loujianwei on 16/9/25.
//  Copyright © 2016年 motianjituan. All rights reserved.
//

#import "MTRecomdAppCell.h"
#import <Masonry.h>
#import "MTRecomdAppItem.h"

@interface MTRecomdAppCell ()

/**  */
//@property (nonatomic, strong)  UIImageView *iconImageView;
//@property (nonatomic, strong)  UILabel *nameLabel;
//@property (nonatomic, strong)  UILabel *resumeLabel;
//@property (nonatomic, strong)  UIButton *downloadBtn;
@end
@implementation MTRecomdAppCell

//应用推荐cell
//- (void)setUpRecomdAppCell {
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {

        //图片
        UIImageView *iconImageView = [[UIImageView alloc] init];
        iconImageView.image = [UIImage imageNamed:@"Icon_dianshang"];
        [self.contentView addSubview:iconImageView];

        UILabel *nameLabel = [[UILabel alloc] init];
        nameLabel.text = @"探米电商";
        nameLabel.font = [UIFont systemFontOfSize:16];
        nameLabel.textColor = [UIColor blackColor];
        [nameLabel sizeToFit];
        [self.contentView addSubview:nameLabel];


        UILabel *resumeLabel = [[UILabel alloc] init];
        resumeLabel.text = @"多快好省, 只为品质生活";
        resumeLabel.font = [UIFont systemFontOfSize:13];
        [resumeLabel sizeToFit];
        resumeLabel.textColor = MTColor(215, 215, 215);
        [self.contentView addSubview:resumeLabel];


        //下载
        UIButton *downloadBtn = [[UIButton alloc] init];
        [downloadBtn setTitle:@"下载" forState:UIControlStateNormal];
        [downloadBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
        [downloadBtn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
        [downloadBtn setBackgroundColor:[UIColor yellowColor]];
//        [downloadBtn setImage:[UIImage imageNamed:@"Btn_Collection"] forState:UIControlStateNormal];
//        [downloadBtn setImage:[UIImage imageNamed:@"arrow"] forState:UIControlStateSelected];
        [downloadBtn sizeToFit];
        [self.contentView addSubview:downloadBtn];
        [downloadBtn addTarget:self action:@selector(clickDownload) forControlEvents:UIControlEventTouchUpInside];

        [iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(self.mas_top).offset(13);
            make.left.equalTo(self.mas_left).offset(13);
            make.width.equalTo(@(74));
            make.height.equalTo(@(74));
        }];
        //商品名字
        [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(iconImageView.mas_right).offset(13);
            make.top.equalTo(self.mas_top).offset(20);
            make.width.equalTo(@(nameLabel.frame.size.width));
            make.height.equalTo(@(nameLabel.frame.size.height));
        }];

        //简介
        [resumeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(iconImageView.mas_right).offset(13);
            make.bottom.equalTo(self.mas_bottom).offset(-20);
            make.width.equalTo(@(resumeLabel.frame.size.width));
            make.height.equalTo(@(resumeLabel.frame.size.height));
        }];

        [downloadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.mas_centerY);
            make.right.equalTo(self.mas_right).offset(-20);
            make.width.equalTo(@(downloadBtn.frame.size.width));
            make.height.equalTo(@(downloadBtn.frame.size.height));
        }];

    }
    return self;
}

- (void)clickDownload {

//    NSString *str = [NSString stringWithFormat:
//                     @"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=%d",
//                     436957167 ];
//    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/us/app/id%d", 436957167];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}

//- (void)setItem:(MTRecomdAppItem *)item {
//
//    _iconImageView.image = [UIImage imageNamed:item.icomImage];
//    _nameLabel.text = item.nameLabel;
//    _resumeLabel.text = item.resumeLabel;
//    _downloadBtn.titleLabel.text = item.downloadBtn;
//}

@end
